import express from "express";
import response from "../models/response";
import UserModel from "../models/user";
const router = express.Router();

/* GET users listing. */
router.get("/list", async (req: any, res: any, next: any) => {
   try {
       const users = await UserModel.find();
       let result = new response.SuccessResponse(users);
       res.json(result);
   } catch (error) {
       res.send(new response.ErrorResponse(-1,'error').toJson());
   }
});

router.post("/", (req: any, res: any, next: any) => {
   let user = new UserModel(req.body);
   user.save();
   let result = new response.SuccessResponse(user, "Hello World!");
   res.send(result.toJson());
});

export default router;
